package com.hoioy.findjob.jvm.gc;

import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;

/**
 * 四种引用类型与范例
 */
public class RefTest {
    public static void main(String[] args) {
        //StrongReference
        Object object = new Object();
        String str = "hello";

        //SoftReference
        SoftReference<String> sr = new SoftReference<>("hello");
        System.out.println(sr.get());

        //WeakReference
        WeakReference<String> wr = new WeakReference<String>("hello");
        System.out.println(wr.get());
        System.gc(); //通知JVM的gc进行垃圾回收，不一定回立即执行
        System.out.println(wr.get());//可能为null,说明被回收

//        https://www.cnblogs.com/dolphin0520/p/3784171.html
    }
}
